// xc_lshop/shop/user/warehouse/index.js
var actbill = require('../../../../xc/model/user_warehouse')

Page({
  mixins: [require('../../../../xc/mixins/basicMixin')],

  /**
   * 页面的初始数据
   */
  data: {
    fold:{},
    navid:0,
    nav:[
      {id:0,name:"全部"},
      {id:1,name:"待处理"},
      {id:2,name:"托售中"},
      {id:3,name:"已完成"},
    ]

  },

  xcloaddata: function (options, config) {
    var update = {};
    console.log("config")
    console.log(config)

    if (config.wholesale) {
      update["wholesaleconfig"] = config.wholesale
    }
    // if (config.payment) {
    //   update["paymentconfig"] = config.payment
    // }
    // if(options.xtid){
    //   update["xtid"] = options.xtid
    // }
    this.setData(update)
    var that=this;
    this.getpagelist(that, 1)

  },
  aftertransaction(){
    var that=this;
    this.getpagelist(that, 1)
  },
  cancel(e){
    var item=e.currentTarget.dataset.item
    // console.log(item)
    // return
    var that=this;
    actbill.cancel(item.proid).then(function (result) {
       console.log("result")
       console.log(result)
       if(result['status']==1){
        wx.showToast({
          title: '操作成功',
        })
        that.getpagelist(that, 1)
       }else{
         wx.showModal({
           title: '错误',
           content:result['message'],
           complete: (res) => {
             
           }
         })
       }

    })
  },
  recovery(e){
    var item=e.currentTarget.dataset.item
    this.selectComponent("#choose").init(item,"recovery")
  },
  sale(e){
    var item=e.currentTarget.dataset.item
    this.selectComponent("#choose").init(item,"sale")
  },
  showspec(e){
    var proid=e.currentTarget.dataset.id
    console.log(this.data.fold[proid])
    this.setData({
      ['fold.'+proid]:!this.data.fold[proid]
    })
  },
  getpagelist(that, rest, strwhere) {
    if (rest == 1) {
      if (!strwhere) {
        strwhere = {};
      }
      strwhere["status"] = 1;
      strwhere["navid"] = this.data.navid;
      strwhere["name"] = this.data.value;
      // strwhere["spid"] = this.data.actspid;
      // strwhere["seachval"] = this.data.seachval;
      that.setData({ modellist: [] ,loadinglist:true});
    }
    actbill.offset(that, rest, strwhere).then(function (result) {
      var updatemdoel = {};

      if ((result["code"] == "over" && result["obj"]) || result["code"] == "loadmore") {

        // var modellist=result["obj"]["modellist"];
        // for(var i in modellist){
        //   for
        // }
        if (rest == 1) {
          updatemdoel["modellist"] = result["obj"]["modellist"];
        }
        else {
          if (result["obj"]["modellist"].length > 0) {
            updatemdoel["modellist"] = that.data.modellist.concat(result["obj"]["modellist"]);
          }
        }
      }
      console.log(updatemdoel)
      wx.stopPullDownRefresh();
      updatemdoel['loadinglist']=false
      that.setData(updatemdoel);
      // that.selectComponent("#choose").init(updatemdoel["modellist"][0],"recovery")

    });
  },
  onChange(e){
     this.setData({
       navid:e.detail.name
     })
     var that = this
     this.getpagelist(that, 1)
  },
/**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this
    this.getpagelist(that, -1)
  },


 
})